package com.gxa.shop.dao.discount.impl;

import com.gxa.shop.bean.vo.DiscountOption;
import com.gxa.shop.commons.jdbc.JDBCUtil;
import com.gxa.shop.dao.discount.DiscountDao;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * com.gxa.shop.bean.dao.impl
 * User: zjy
 * Date: 2024/12/19 21:45
 * motto:   逆水行舟不进则退
 * Description:
 * Version: V1.0
 */
public class DiscountDaoImpl implements DiscountDao {
    @Override
    public List<DiscountOption> findAllList() {
        String sql="select discount_id,discount_rate,discount_name from discount";
        JDBCUtil jdbcUtil=new JDBCUtil();
        List<Map<String, Object>> query = jdbcUtil.query(sql);
        if(query.size()>0){
            List<DiscountOption> list=new ArrayList<>();
            for (Map<String, Object> row : query) {
                DiscountOption  discountOption=new DiscountOption();
                discountOption.setDiscountId((Integer) row.get("discount_id"));
                discountOption.setDiscountRate((Double) row.get("discount_rate"));
                discountOption.setDiscountName((String) row.get("discount_name"));
                list.add(discountOption);
            }
            return  list;
        }
        return null;
    }
}